package com.wmd.core.extendtions;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * Simple to Introduction
 *
 * @projectName:DocumentLibrary
 * @packageName:com.wmd.core.extendtions
 * @className:StreamExtendtions
 * @Description:[一句话描述该类的功能]
 * @Author:luyincheng
 * @CreateDate:2021/10/25 13:52
 * @blog:[方法具体上行/下行参数文档]
 */
public class StreamExtendtions {


    public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object,Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
}
